package com.example.administrator.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;


/**
 * Created by Administrator on 2016/3/22 0022.
 */
public class MyExpandableAdapter extends BaseExpandableListAdapter {
    private Context mContext;
    private List<List<News>> mList;
    private String[] mNews;
    private LayoutInflater mInFlater;
    public MyExpandableAdapter(Context context,List<List<News>> list,String[] news){
        mInFlater = LayoutInflater.from(context);
        mContext = context;
        mList = list;
        mNews = news;
    }
    @Override
    public int getGroupCount() {
        return mNews.length;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return mList.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        TextView tv_group = new TextView(mContext);
        tv_group.setPadding(50,30,0,0);
        tv_group.setTextSize(25);
        tv_group.setText(mNews[groupPosition]);
        return tv_group;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        //将布局加载成View
        convertView = mInFlater.inflate(R.layout.list_expandable_item,null);
        //找到控件
        TextView tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
        TextView tvContent = (TextView) convertView.findViewById(R.id.tv_content);
        ImageView imageIcon = (ImageView) convertView.findViewById(R.id.imageView1);
        //赋值
        News news = mList.get(groupPosition).get(childPosition);
        tvTitle.setText(news.getTitle());
        tvContent.setText(news.getTitle());
        imageIcon.setImageResource(news.getPicId());
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
}
